/**
 * ***********************************************************************************
 * [Project]
 * MyProgressDialog
 * [Package]
 * com.lxd.widgets
 * [FileName]
 * CustomProgressDialog.java
 * [Copyright]
 * Copyright 2012 LXD All Rights Reserved.
 * [History]
 * Version          Date              Author                        Record
 * --------------------------------------------------------------------------------------
 * 1.0.0           2012-4-27         lxd (rohsuton@gmail.com)        Create
 * ************************************************************************************
 */

package com.ydkj.a37e_mall.Resource.View;


import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.widget.TextView;

import com.ydkj.a37e_mall.R;


/**
 * *****************************************************************
 * [Summary]
 * TODO 请在此处简要描述此类所实现的功能。因为这项注释主要是为了在IDE环境中生成tip帮助，务必简明扼要
 * [Remarks]
 * TODO 请在此处详细描述类的功能、调用方法、注意事项、以及与其它类的关系.
 * *****************************************************************
 */

public class CustomProgressDialog extends Dialog {
    private Context context = null;
    private static CustomProgressDialog customProgressDialog = null;

    public CustomProgressDialog(Context context) {
        super(context);
        this.context = context;
    }

    public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }

    public static CustomProgressDialog createDialog(Context context) {
        customProgressDialog = new CustomProgressDialog(context, R.style.CustomProgressDialog);
        customProgressDialog.setContentView(R.layout.custom_progress_dialog);
        customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;
        customProgressDialog.setCancelable(false);//点击对话框外面和按返回键对话框不会消失
        return customProgressDialog;
    }

    public void Show() {
        customProgressDialog.show();
    }

    public static void Dismiss() {
        customProgressDialog.dismiss();
    }

    public void onWindowFocusChanged(boolean hasFocus) {

        if (customProgressDialog == null) {
            return;
        }

//        ImageView img_loading = (ImageView) customProgressDialog.findViewById(R.id.img_loading);
//        AnimationDrawable animationDrawable = (AnimationDrawable) img_loading.getBackground();
//        animationDrawable.start();
    }

    /**
     * [Summary]
     * setTitile 标题
     *
     * @param strTitle
     * @return
     */
    public CustomProgressDialog setTitile(String strTitle) {
        return customProgressDialog;
    }

    /**
     * [Summary]
     * setMessage 提示内容
     *
     * @param strMessage
     * @return
     */
    public CustomProgressDialog setMessage(String strMessage) {
        TextView tv_loadingmsg = (TextView) customProgressDialog.findViewById(R.id.tv_loadingmsg);

        if (tv_loadingmsg != null) {
            tv_loadingmsg.setText(strMessage);
        }

        return customProgressDialog;
    }
}